Repository navigation
feat: add user subcommands for account recovery - #1095
Conversation
Add `gotify user create [--admin] <name> [password]`, `gotify user set-password <name> [password]` and `gotify user set-admin <name> true|false`. They load the same config as `gotify serve` and operate directly on the configured database, so a lost admin account can be recovered without API access. If the password is omitted, it is prompted for twice without echo. If stdin is not a terminal, the command fails instead of hanging. Passwords are validated and hashed like in the API. The commands never create the default user, so on an empty database only the requested change is made. Fixes gotify#1043
3a5e6c2 to
da1551b
Compare
|
@jmattheis a gentle ping. I rebased this onto current master today, so it includes the elevate change. The build workflow is waiting for a maintainer to approve the run since this is my first PR here. Could you approve it and take a look when you have a moment? The docs side is in gotify/website#110. |
|
Yeah, it's on my todo list, but in the last two weeks I had not much time for open source and there is quite a lot in my backlog. On first glance it looks okay. |
|
totally understandable! take your time |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1095 +/- ##
==========================================
+ Coverage 81.82% 82.45% +0.62%
==========================================
Files 69 70 +1
Lines 3290 3419 +129
==========================================
+ Hits 2692 2819 +127
- Misses 598 600 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes #1043
This adds the
usersubcommands that @jmattheis proposed in the issue, so a lost admin account can be recovered without access to the API:If
[password]is omitted, it is prompted for twice without echo. If stdin isn't a terminal, the command exits with an error instead of hanging. Passwords go through the sameValidateNewPassword/CreatePassword(withGOTIFY_PASSSTRENGTH) as the API. The commands load the config exactly likeserve(env vars and env files), so they hit the same database.Example, recovering the admin in Docker:
Some notes:
createDefaultUserIfNotExist=false, so running a command against an empty database doesn't also createadmin:admin. It only makes the requested change.set-admin <name> falsecurrently follows the spec and doesn't stop you from demoting the last admin, while the API refuses that ("cannot delete last admin"). I can add the same check here if you'd prefer. You could always promote a user again with the CLI.golang.org/x/termfor the password prompt, at the versionx/cryptoalready requires.I tested on a clean Ubuntu 24.04 VM with Go 1.27.4:
make test-coverageandmake check-go(golangci-lint v2.15.0)serve, rancreate(argument and real terminal prompt),create --admin,set-password adminandset-admin alice true, then checked over the API that the old admin password returns 401, the new one 200, and alice is admin. Also checked all the error cases and their exit codes.docker/Dockerfileand recovered the admin withdocker exec -it gotify ./gotify-app user set-password admin.set-password,createandset-admin, then verified via the API.Docs: gotify/website#110 describes how to reset a lost admin password with these commands.